<!-- 企业信息审核详情 -->
<template>
  <div class="detail-index-content">
    <HeadLabel title="企业信息审核详情" routeName="enterpriseInforExamine" />
    <div class="page-main-content">
      <div
        class="page-main-content-head"
        v-if="formData.auditStatus == 'UnderReview'"
      >
        <BtnBox isIcon type="light-blue" :text="formData.auditStatusName" />
        <BtnText type="primary">更新时间 {{ formData.updateDateTime }}</BtnText>
      </div>
      <h2>
        <span>企业名称</span>
        <BtnText type="primary" @BtnClick="modelValueHistory = true"
          >变更历史记录</BtnText
        >
      </h2>
      <Divider />
      <h3>企业基本信息</h3>
      <div class="page-main-form-box">
        <Row>
          <Col span="8">
            <MainFormItem title="企业名称">{{
              formData.companyName
            }}</MainFormItem>
          </Col>
          <Col span="8"
            ><MainFormItem title="上级组织">{{
              formData.parentName
            }}</MainFormItem></Col
          >
          <Col span="8"
            ><MainFormItem title="证件类型">{{
              formData.companyCardTypeName
            }}</MainFormItem></Col
          >
          <Col span="8"
            ><MainFormItem title="证件号码">{{
              formData.companyCardNumber
            }}</MainFormItem></Col
          >
          <Col span="8"
            ><MainFormItem title="注册地址">{{
              formData.companyAddress
            }}</MainFormItem></Col
          >
          <Col span="8"
            ><MainFormItem title="证件照片">
              <ViewImg
                isPreview
                isIcon
                errorMsg="证件照片"
                :fileList="formData.companyIdFiles"
              ></ViewImg> </MainFormItem
          ></Col>
          <Col span="24"
            ><MainFormItem title="业务范围">{{
              formData.businessRange
            }}</MainFormItem></Col
          >
        </Row>
      </div>
      <Divider />
      <h3>企业服务能力</h3>
      <div class="page-main-form-box">
        <Row>
          <Col span="24"
            ><MainFormItem title="服务地区">
              {{ serviceAreaFn(formData.serviceArea) }}
            </MainFormItem></Col
          >
          <Col span="24"
            ><MainFormItem title="产业标记">
              {{ serviceTypeFn(formData.serviceType) }}</MainFormItem
            ></Col
          >
        </Row>
      </div>
      <Divider />
      <h3>企业资质</h3>
      <div class="page-main-form-box page-main-form-table">
        <Table :columns="columns" :data="formData.companyAptitudeHistoryVos">
          <template slot-scope="{ row }" slot="file">
            <ViewImg
              isPreview
              errorMsg="资质附件"
              :fileList="row.files"
            ></ViewImg>
          </template>
        </Table>
      </div>
      <Divider />
      <h3>企业收益规则</h3>
      <div class="page-main-form-box">
        <Row>
          <Col span="12"
            ><MainFormItem title="规则说明">
              <!-- {{ formData.companyRuleFiles }} -->
              <ViewImg
                isPreview
                errorMsg="规则说明"
                :fileList="formData.companyRuleFiles.files"
              ></ViewImg></MainFormItem
          ></Col>
          <Col span="12"
            ><MainFormItem title="收益规则"
              >{{ formData.companyDivideIntoRuleValue }}%</MainFormItem
            ></Col
          >
        </Row>
      </div>
      <Divider />
      <div
        class="page-main-content-footer"
        v-if="formData.auditStatus == 'UnderReview'"
      >
        <BtnBox
          isIcon
          type="light-blue"
          text="拒绝"
          @BtnClick="handleAction(formData, 3)"
        />
        <BtnBox isIcon text="通过" @BtnClick="handleAction(formData, 2)" />
      </div>
    </div>
    <HistoryChange
      v-model="modelValueHistory"
      :companyId="formData.companyId"
    />
  </div>
</template>

<script type="text/javascript">
import {
  GetCheckCompanyDetail, // 变更前后数据
} from "@/api/enterpriseInforManage.js";
import HistoryChange from "@/pages/components/historyChange";

import {
  GetCheckCompanyInfo, // 企业审核
} from "@/api/enterpriseInforManage.js";

import { returnStr } from "@/libs/util.js";

export default {
  name: "enterpriseInforInquiry",
  components: { HistoryChange },
  data() {
    return {
      formData: {
        auditStatus: "",
        auditStatusName: "",
        baseStatus: "",
        baseStatusName: "",
        businessLicenseImages: "",
        city: "",
        companyAddress: "",
        companyCardNumber: "",
        companyCardTypeName: "",
        companyCnSimpleName: "",
        companyCode: "",
        companyEnSimpleName: "",
        companyId: "",
        companyIdFiles: [],
        companyItems: [],
        companyLevel: "",
        companyLevelName: "",
        companyName: "",
        companyRuleFiles: [],
        contactMobile: "",
        contactPerson: "",
        createDateTime: "",
        createUserName: "",
        district: "",
        isDel: false,
        logoUrl: "",
        parentId: "",
        province: "",
        rootId: "",
        ruleStatus: "",
        ruleStatusName: "",
        serviceArea: [],
        serviceType: [],
        companyAptitudeFiles: [],
        status: "",
        statusName: "",
        street: "",
        updateDateTime: "",
        updateUserName: "",
      },
      columns: [
        {
          title: "资质名称",
          key: "companyAptitudeName",
        },
        {
          title: "等级",
          key: "lv",
        },
        {
          title: "资质附件",
          slot: "file",
        },
        {
          title: "有效期截止时间",
          key: "validEndDate",
        },
      ],
      columnsRecord: [
        {
          title: "项目名称",
          key: "projectName",
        },
        {
          title: "重复率",
          slot: "rate",
        },
        {
          title: "业主方",
          key: "ownerCompanyName",
        },
        {
          title: "施工方",
          key: "constructionName",
        },
        {
          title: "项目地址",
          key: "projectAddressName",
        },
        {
          title: "预计产值规模(万元)",
          key: "outputScale",
        },
        {
          title: "发布时间",
          key: "createDateTime",
        },
      ],
      listData: [],
      modelValueHistory: false,
      companyId: "",
    };
  },
  methods: {
    serviceAreaFn(data) {
      return returnStr(data, "provinceName", "cityName");
    },
    serviceTypeFn(data) {
      return returnStr(data, "serviceTypeName");
    },
    // 获取企业信息详情
    async getCheckCompanyDetailData() {
      let { query } = this.$route;
      let id = query.id;
      let params = {
        id,
      };
      let data = await GetCheckCompanyDetail(params);
      this.formData = data;
    },
    // 变更记录
    changeLog() {
      let { id: companyId } = this.$route.query;
      this.$router.push({
        path: "/changeRecord",
        query: {
          companyId,
          changeType: 1,
        },
      });
    },
    // 查看详情
    viewDetail(row) {},
    handleAction(row, types) {
      console.log(types, "types");
      if (types == 1) {
        this.$router.push({
          name: "enterpriseDetail",
          query: {
            id: row.id,
          },
        });
        return;
      }
      if (types == 2) {
        this.$Modal.confirm({
          title: "审核通过",
          content: "<p>确定审核通过吗？</p>",
          loading: true,
          onOk: async () => {
            let params = {
              id: row.id,
              auditStatus: 2,
            };
            let that = this;
            try {
              let data = await GetCheckCompanyInfo(params);
              this.$tips(
                {
                  iconName: "icon_1",
                  text: "审核通过",
                },
                function handleClose(data) {
                  that.getCheckCompanyDetailData();
                }
              );
              this.$Modal.remove();
            } catch (error) {
              this.$Modal.remove();
            }
          },
        });
      }
      if (types == 3) {
        let that = this;

        this.$tips(
          {
            iconName: "icon_2",
            text: "审核已拒绝",
            isArgument: true,
          },
          // 点击确定的按钮回调
          async function handleSubmit(ev, value) {
            if (!value) return that.$Message.error("请输入拒绝理由");
            try {
              let params = {
                id: row.id,
                auditStatus: 3,
                rejectReason: value,
              };
              let data = await GetCheckCompanyInfo(params);
              ev.remove();
              that.$tips(
                {
                  iconName: "icon_2",
                  text: "审核拒绝",
                },
                function handleClose(data) {
                  that.getCheckCompanyDetailData();
                }
              );
            } catch (error) {
              ev.remove();
            }
          }
        );
      }
    },
  },
  created() {
    this.getCheckCompanyDetailData();
  },
};
</script>

<style lang="less" scoped>
.page-main-content {
  padding: 20px;
  background: #fff;
  border-radius: 6px;
}
.page-main-content-head {
  border: none;
}
.page-main-content-footer {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  .btn-box-main {
    margin-left: 15px;
  }
}
h2 {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
